//生成32位随机数UUID
export const getRandomStrNum = () => {
    var s = [];
    var hexDigits = "0123456789abcdef";
    for (var i = 0; i < 32; i++) {
      s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
    }
    s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
    s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
    s[8] = s[13] = s[18] = s[23];
  
    var uuid = s.join("");
    return uuid;
  };
  
  const utf16to8 = (str: string) => {
    var out, i, len, c;
    out = "";
    len = str.length;
    for (i = 0; i < len; i++) {
      c = str.charCodeAt(i);
      if (c >= 0x0001 && c <= 0x007f) {
        out += str.charAt(i);
      } else if (c > 0x07ff) {
        out += String.fromCharCode(0xe0 | ((c >> 12) & 0x0f));
        out += String.fromCharCode(0x80 | ((c >> 6) & 0x3f));
        out += String.fromCharCode(0x80 | ((c >> 0) & 0x3f));
      } else {
        out += String.fromCharCode(0xc0 | ((c >> 6) & 0x1f));
        out += String.fromCharCode(0x80 | ((c >> 0) & 0x3f));
      }
    }
    return out;
  };
  
  const base64_encode = function base64_encode(str: string) {
    //下面是64个基本的编码
    var base64EncodeChars =
      "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
    var out, i, len;
    var c1, c2, c3;
    len = str.length;
    i = 0;
    out = "";
    while (i < len) {
      c1 = str.charCodeAt(i++) & 0xff;
      if (i == len) {
        out += base64EncodeChars.charAt(c1 >> 2);
        out += base64EncodeChars.charAt((c1 & 0x3) << 4);
        out += "==";
        break;
      }
      c2 = str.charCodeAt(i++);
      if (i == len) {
        out += base64EncodeChars.charAt(c1 >> 2);
        out += base64EncodeChars.charAt(((c1 & 0x3) << 4) | ((c2 & 0xf0) >> 4));
        out += base64EncodeChars.charAt((c2 & 0xf) << 2);
        out += "=";
        break;
      }
      c3 = str.charCodeAt(i++);
      out += base64EncodeChars.charAt(c1 >> 2);
      out += base64EncodeChars.charAt(((c1 & 0x3) << 4) | ((c2 & 0xf0) >> 4));
      out += base64EncodeChars.charAt(((c2 & 0xf) << 2) | ((c3 & 0xc0) >> 6));
      out += base64EncodeChars.charAt(c3 & 0x3f);
    }
    return out;
  };
  
  export const baseEncode = (str: string) => {
    return base64_encode(utf16to8(str));
  };
  
  export const checkTimeRange = () => {
    const now = new Date();
    const hours = now.getHours();
    const minutes = now.getMinutes();
    console.log("hours", hours);
    console.log("minutes", minutes);
    // 把小时和分钟转换成总分钟数以便进行范围比较
    const totalMinutes = hours * 60 + minutes;
  
    if (totalMinutes >= 0 && totalMinutes <= 540) {
      // 00:00 - 09:00 (总分钟数 0 到 540)
      return 1;
    } else if (totalMinutes >= 541 && totalMinutes <= 900) {
      // 09:01 - 15:00 (总分钟数 541 到 900)
      return 2;
    } else if (totalMinutes >= 901 && totalMinutes <= 1439) {
      // 15:01 - 23:59 (总分钟数 901 到 1439)
      return 3;
    }
  };